//
//  WelcomeView.swift
//  Practice
//
//  Created by miaozhihui on 2017/2/6.
//  Copyright © 2017年 DeKuTree. All rights reserved.
//

import UIKit
import SDWebImage

class WelcomeView: UIView {
    
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var tipLabel: UILabel!
    @IBOutlet weak var bottomCons: NSLayoutConstraint!
    
    class func welcomeView() -> WelcomeView {
        
        let nib = UINib(nibName: "WelcomeView", bundle: nil)
        
        let v = nib.instantiate(withOwner: nil, options: nil)[0] as! WelcomeView
        
        v.frame = UIScreen.main.bounds
        
        return v
    }
    
    override func awakeFromNib() {
        iconView.zh_setImage(urlString: NetworkTools.sharedTools.userAccount.avatar_large, placeholderImage: UIImage(named: "avatar_default_big")!, isDrawCircle: true)
    }
    
    override func didMoveToWindow() {
        super.didMoveToWindow()
        // 调用layoutIfNeeded()会更新布局
        self.layoutIfNeeded()
        bottomCons.constant = bounds.height - 200
        UIView.animate(withDuration: 3.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            // 更新约束
            self.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 1.0, animations: { 
                self.tipLabel.alpha = 1
            }, completion: { (_) in
                self.removeFromSuperview()
            })
            
        }
    }
}
